package cn.itcast.utils;

import org.springframework.core.convert.converter.Converter;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringToDate implements Converter<String, Date> {

    @Override
    public Date convert(String source) {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        if (source==null){
            throw new RuntimeException("日期数据输入有误");
        }
        try {
            Date date = format.parse(source);
            return date;
        } catch (ParseException e) {
            throw new RuntimeException("日期数据输入有误");
        }

    }
}
